'''
Description: 
Author: Zilu
Date: 2021-11-18 11:33:39
Version: 
LastEditTime: 2021-11-18 12:35:04
LastEditors: Zilu
'''

# Flask通过render_template()函数来实现模板的渲染，默认模板是 jinja2
import re
from flask import Flask, request, render_template

app = Flask(__name__)

# Flask通过Python的装饰器在内部自动地把URL和函数给关联起来
@app.route('/', methods=['GET', 'POST'])
def home():
    return render_template('home.html')

@app.route('/signin', methods=['GET'])
def signin_form():
    return render_template('form.html')

@app.route('/signin', methods=['POST'])
def signin():
    # 需要从request对象读取表单内容
    # Flask通过request.form['name']来获取表单的内容
    username = request.form['username']
    password = request.form['password']
    if username == 'admin' and password == 'password':
        return render_template('signin-ok.html', username = username)
    return render_template('form.html', message='Bad username or password', username=username)

# 所有模板文件放在templates文件夹下

if __name__ == '__main__':
    app.run()


